package com.zretc.controller;

import com.github.pagehelper.PageInfo;
import com.zretc.entity.Cinema;
import com.zretc.entity.Movie;
import com.zretc.service.CinemaFirstPageService;
import com.zretc.service.MovieFirstPageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author qizoahiyu
 * @date 2020-7-22
 */
@Controller
@RequestMapping("/getMovie")
public class MovieFirstPageController {

    private static  final Logger logger = LoggerFactory.getLogger(MovieFirstPageController.class);

    @Autowired
    private MovieFirstPageService movieFirstPageService;
    @Autowired
    private CinemaFirstPageService cinemaFirstPageService;

    @RequestMapping("/moviePage")
    @ResponseBody
    public PageInfo<Movie> getMovieList(@RequestParam(value = "pageNum") String pageNum,
                                        @RequestParam(value = "pageSize") String pageSize,
                                        @RequestParam(value = "showStatus") String showStatus){
        // 2.调用业务层
        Map<String, String> map = new HashMap<>();
        map.put("pageNum",pageNum);
        map.put("pageSize",pageSize);
        map.put("showStatus",showStatus);

        PageInfo<Movie> movieByStatus = movieFirstPageService.getMovieByStatus(map);

        //logger.info(movieByStatus.toString());

        return movieByStatus;
    }

    @RequestMapping("/cinemaPage")
    @ResponseBody
    public PageInfo<Cinema> getCinemaList(@RequestParam(value = "pageNum") String pageNum,
                                          @RequestParam(value = "pageSize") String pageSize){

        // 2.调用业务层
        Map<String, String> map = new HashMap<>();
        map.put("pageNum",pageNum);
        map.put("pageSize",pageSize);

        PageInfo<Cinema> cinemaDescPage = cinemaFirstPageService.getCinemaDescPage(map);

        return cinemaDescPage;

    }

    @RequestMapping("/upComingMovie")
    @ResponseBody
    public List<Map<String,Object>> getUpComingMovie(@RequestParam(value = "startTime") String startTime){

        // 调用业务层
        List<Map<String,Object>> movieByStartTime = movieFirstPageService.getMovieByStartTime(startTime);

        // 判断集合是否为空
        if(movieByStartTime == null){
            return null;
        } else{
            return movieByStartTime;
        }

        //return movieByStartTime;
    }
}
